function HandleTableProduceHistory(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  this._user = (options && options.user) ? options.user : null;
  this._date = (options && options.date) ? options.date : null;
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._noLog = (options && options.noLog) ? options.noLog : null;
    
  this._createElements();
};

HandleTableProduceHistory.prototype._createElements = function() {
  var valid, track, a, model, state, _self = this;
  
  DOMUtils.removeTableRows(this._gui.main, 1);
  
  if (this._item.v2_events.length == 0) {
    tr = this._gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 4;
    td.style.height = '24px';
    td.style.backgroundColor = '#ebebe3';
    td.style.borderLeft = 'solid 1px #b4b4b4';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }
  
  if (this._noLog) {
    this._gui.title.appendChild(document.createTextNode(this._item.name));
    this._gui.reverse.appendChild(document.createTextNode('Reverse is not permitted, ' + ((track) ? (track.userAccount + ' ' + DlmanageUtils.text(Manage.map(), this._item.pi_model, track.sourceId, track.targetId, track.extra)) : ' (None)')));
  } else {
    this._transitions = [];
    model = Manage.map()[this._item.pi_model];
    for (var i = 0, il = model.states.length; i < il; i++) {
      var s = model.states[i];
      if (this._item.state == s.id) {
        state = s;
        break;
      }
    }
    for (var i = 0, il = model.transitions.length; i < il; i++) {
      var t = model.transitions[i];
      if (this._item.state == t.source.id) {
        this._transitions[this._transitions.length] = t;
      }
    }
  
    MiscUtils.sort(this._item.v2_tracks, ['id']);
    MiscUtils.sort(this._item.v2_events, ['id']);
    
    track = (this._item.v2_tracks.length > 0) ? this._item.v2_tracks[this._item.v2_tracks.length - 1] : null
    
    this._gui.title.appendChild(document.createTextNode(this._item.title));
    
    for (var i = 0, il = this._item.v2_events.length; i < il; i++) {
      var event = this._item.v2_events[this._item.v2_events.length - 1 - i];

      var tr = this._gui.main.insertRow(-1);
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'center';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(SimpleDate.format(event.date)));
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.userAccount));
      var str = DlmanageUtils.text(Manage.map(), this._item.pi_model, event.sourceId, event.targetId, '');
      if (str != '') {
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(str));
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(event.extra + ((event.extra && event.overdueReason) ? ' / ' : '') + ((event.overdueReason) ? 'Overdue Reason: ' + event.overdueReason : '')));
      } else {
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        td.style.height = '25px';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.verticalAlign = 'middle';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
        td.appendChild(document.createTextNode(event.extra + ((event.extra && event.overdueReason) ? ' / ' : '') + ((event.overdueReason) ? 'Overdue Reason: ' + event.overdueReason : '')));
        td = tr.insertCell(-1);
        td.style.borderRight = 'solid 1px #b4b4b4';
        td.style.borderBottom = 'solid 1px #b4b4b4';
        td.style.height = '25px';
        td.style.verticalAlign = 'middle';
        td.style.textAlign = 'left';
        td.style.paddingLeft = '15px';
        td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      }
    }
    
    valid = false;
    if (track) {
      for (var i = 0, il = this._transitions.length; i < il; i++) {
        var t = this._transitions[i];
        if (t.validate(this._item, this._user, this._date, null)) {
          valid = true;
        }
      }
      valid = (track.userTrackId == this._user.trackId) ? true : valid;
    }
    
    if ((this._item.pi_model == Constant.MODEL_NAME_PRODUCT_COMMON && (this._item.state == 15 || this._item.state == 16 || this._item.state == 17)) || 
        (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_RETOUCH_MAGAZINE && (this._item.state == 15 || this._item.state == 16 || this._item.state == 17)) || 
        (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_4X6 && (this._item.state == 9 || this._item.state == 10 || this._item.state == 11)) ||
        (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_VIDEODVD && (this._item.state == 4 || this._item.state == 5 || this._item.state == 6)) ||
        (this._item.pi_model == Constant.MODEL_NAME_USER_VIDEOGRAPHER && (this._item.state == 7 || this._item.state == 8)) ||
        this._item.pi_model == Constant.MODEL_NAME_MAIL || this._item.pi_model == Constant.MODEL_NAME_CUSTOM) {
      valid = false;
    }
    
    if (this._item.cancelled == 1) {
      valid = false;
    }
    
    if (valid) {
      this._gui.reverse.appendChild(document.createTextNode(track.userAccount + ' ' + DlmanageUtils.text(Manage.map(), this._item.pi_model, track.sourceId, track.targetId, track.extra)));
      a = document.createElement('a');
      a.href = '#';
      a.style.margin = '0 0 0 5px';
      a.appendChild(document.createTextNode('Reverse'));
      a.onclick = function() { var div, pos, func1, func2;
                               func1 = function() { if (_self._item._text == '') {
                                                      window.alert('CAN NOT BE EMPTY');
                                                      return;
                                                    }
                                                    var e = ProduceEvent.instance();
                                                    e.produce_trackId = _self._item.trackId;
                                                    e.date = _self._date;
                                                    e.userAccount = _self._user.account;
                                                    e.extra = '[R] ' + DlmanageUtils.text(Manage.map(), _self._item.pi_model, track.sourceId, track.targetId, track.extra) + '/' + _self._item._text + '';
                                                    var pUsers = [];
                                                    var produce = DlmanageUtils.reverse(_self._item, track);
                                                    if (_self._item.pi_model == '{{$smarty.const.MODEL_NAME_PRECON|escape:javascript}}') {
                                                      pUsers = DlmanageUtils.getProduceUser(_self._item, track);
                                                    }
                                                    new RequestUtils()._write2([{ n: 'produce', a: [produce], r: [] }, { n: 'produceevent', a: [e], r: [] }, { n: 'producetrack', a: [], r: [track] }, { n: 'produceuser', a: pUsers, r: _self._item.pUsers }, { n: 'producetrackuser', a: [], r: track.pUsers }], _self._callbackFunc, { php: Constant.FACTORY + '/customphp/mysqlwrite2.php', pos: pos });
                                                    _self._popupBox2._close();
                                                  }
                               var func2 = function() { _self._popupBox2._close(); };
                               pos = DOMUtils.findPos(this);
                               div = document.createElement('div');
                               MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Reason'});
                               new DialogInput(div, _self._item, { title: '' });
                               return false;
                             };
      this._gui.reverse.appendChild(a);
    } else {
      this._gui.reverse.appendChild(document.createTextNode('Reverse is not permitted, ' + ((track) ? (track.userAccount + ' ' + DlmanageUtils.text(Manage.map(), this._item.pi_model, track.sourceId, track.targetId, track.extra)) : ' (None)')));
    }
  }
};